<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: chen
  Date: 20-2-17
  Time: 下午4:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
\
<html>
<head>
    <title>注册信息</title>
</head>
<body>
<%
    //编码方式
    request.setCharacterEncoding("UTF-8");
    //接收
    String id = request.getParameter("uid");
    String name = request.getParameter("uname");
    String clientname = request.getParameter("username");
    String clientpwd = request.getParameter("upwd");
%>
注册成功，信息如下：<br/>
id:<%= id %><br/>
姓名:<%= name %><br/>
username：<%= clientname %><br/>
passw：<%= clientpwd %><br/>
返回登录页面:<a href="Login.jsp" >返回登录界面</a>
<%!
    private PreparedStatement pmst;
    private Connection conn;
%>
<%
    try {
        Class.forName("com.mysql.jdbc.Driver");  ////加载数据库驱动
        //指向数据库client
        String url = "jdbc:MySQL://localhost:3306/client?&useSSL=false&serverTimezone=UTC";
        String username = "root";  //数据库用户名
        String password = "123456";  //数据库用户密码
        conn = DriverManager.getConnection(url, username, password);  //连接数据库
        String sql = "insert into user(id,name,username,password) values(?,?,?,?)";
        if(conn!=null){
            out.println("mysql数据库连接成功！！！");
            out.println("-------------------------------");
            //3.创建PreparedStatement对象
            pmst = conn.prepareStatement(sql);
            pmst.setString(1,id);
            pmst.setString(2,name);
            pmst.setString(3,clientname);
            pmst.setString(4,clientpwd);
            pmst.executeUpdate();
        }else{
            out.println("数据库连接失败！！！");
        }
    }catch (Exception e) {
        out.print("数据库连接异常");
    }
    finally {
        try {
            // 最后一定要记得在finally代码块中，尽快在执行完SQL语句之后，就释放数据库连接
            if (pmst != null){
                pmst.close();
            }
            if (conn !=null){
                conn.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
%>
</body>
</html>
